#!/usr/bin/env python

import time
import fuse
import stat

# Use same timestamp for all files  
_file_timestamp = int(time.time())

#
#  Convert DateTime to a unix integer
#
def convert2sex(dt):
   return time.mktime(dt.timetuple())

# Special Dummy attribs for a pseudo or virtual directory
class DirStat(fuse.Stat):  
   """ 
   Convenient class for Stat objects. 
   Set up the stat object with appropriate 
   values depending on constructor args. 
   """  
   def __init__(self):  
      fuse.Stat.__init__(self)  
      self.st_mode = stat.S_IFDIR | 0555  
      self.st_nlink = 2
      # dummy times
      self.st_atime = _file_timestamp  
      self.st_mtime = _file_timestamp  
      self.st_ctime = _file_timestamp  

class FATStat(fuse.Stat):
   def __init__(self, fatde): 
      fuse.Stat.__init__(self)  
      if fatde.isDirectory():  
         self.st_mode = stat.S_IFDIR | 0555  
         self.st_nlink = 2  
      else:  
         self.st_mode = stat.S_IFREG | 0444  
         self.st_nlink = 1  
         self.st_size = fatde.size
         
      self.st_atime = convert2sex(fatde.access)
      self.st_mtime = convert2sex(fatde.modtime)
      self.st_ctime = convert2sex(fatde.createtime)
